package day13;

import java.io.Serializable;

/**本类用来封装学生类*/
/*本类如果想要实现序列化,必须实现可序列化接口,否则报错
* 报错信息:NotSerializableException: cn.tedu.seri.Student
* Serializable是一个空接口,里面一个方法都没有,作用:当做标志,标志着这个类可以被序列化*/
public class Student implements Serializable {
    /*x需要给每个进行序列化的文件分配唯一的UID值*/
    //private static final long serialVersionUID = 1l;
    //1.定义并封装属性,提供get()与set()
    private int sno;//学号
    private String name;//姓名
    private String address;//住址
    private char gender;//性别
    //2.提供无参构造--必须手动提供无参构造,否则会被含参构造覆盖
    /*右键空白处->Generate->Constructor->Select None->OK生成即可*/
    public Student() {
        System.out.println("我是Student的无参构造");
    }
    /*右键空白处->Generate->Constructor->按住Shift全选->OK生成即可*/
    public Student(int sno, String name, String address, char gender) {
        this.sno = sno;
        this.name = name;
        this.address = address;
        this.gender = gender;
        System.out.println("我是Student的全参构造");
    }

    /*右键空白处->Generate->Getter and Setter->按住Shift全选->OK生成即可*/
    public int getSno() {
        return sno;
    }

    public void setSno(int sno) {
        this.sno = sno;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }
    /*打印结果:cn.tedu.seri.Student@6d03e736
    * 想看对象的属性值,需要重写toString()*/
    /*右键空白处->Generate->toString->OK生成即可*/
    @Override
    public String toString() {
        return "Student{" +
                "sno=" + sno +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", gender=" + gender +
                '}';
    }
}
